/** 
 * RangePane.java
 * @author Lex
 * 2007-8-27 ����01:52:05
 */
package fun.ui.canvas.control;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import org.lex.swing.widgets.JLabelSeparator;

import fun.ui.canvas.CanvasPane;
import fun.ui.canvas.YAxisPolicy;

public class RangesPane extends JPanel {
	private JLabelSeparator xAxisLabel = null;
	private JLabel xMinLabel = null;
	private JTextField xMinTextField = null;
	private JLabel xMaxLabel = null;
	private JTextField xMaxTextField = null;
	private JLabelSeparator yAxisLabel = null;
	private JLabel policyLabel = null;
	private JComboBox policyComboBox = null;
	private JLabel yMinLabel = null;
	private JTextField yMinTextField = null;
	private JLabel yMaxLabel = null;
	private JTextField yMaxTextField = null;
	private JPanel gluePane = null;
	private JPanel buttonsPane = null;
	private JButton okButton = null;
	private JButton cancelButton = null;
	// ==================================
	private CanvasPane canvas = null;

	public RangesPane(CanvasPane canvas) {
		super();
		this.canvas = canvas;
		initialize();
	}

	private void initialize() {
		GridBagConstraints gridBagConstraints121 = new GridBagConstraints();
		gridBagConstraints121.gridx = 0;
		gridBagConstraints121.gridwidth = 4;
		gridBagConstraints121.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints121.weightx = 10.0;
		gridBagConstraints121.gridy = 6;
		GridBagConstraints gridBagConstraints12 = new GridBagConstraints();
		gridBagConstraints12.gridx = 0;
		gridBagConstraints12.fill = GridBagConstraints.BOTH;
		gridBagConstraints12.weightx = 10.0;
		gridBagConstraints12.weighty = 10.0;
		gridBagConstraints12.gridwidth = 4;
		gridBagConstraints12.gridy = 5;
		GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
		gridBagConstraints11.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints11.gridy = 4;
		gridBagConstraints11.weightx = 0.0;
		gridBagConstraints11.insets = new Insets(0, 5, 5, 5);
		gridBagConstraints11.ipadx = 0;
		gridBagConstraints11.gridx = 3;
		GridBagConstraints gridBagConstraints10 = new GridBagConstraints();
		gridBagConstraints10.gridx = 2;
		gridBagConstraints10.insets = new Insets(0, 5, 5, 0);
		gridBagConstraints10.anchor = GridBagConstraints.EAST;
		gridBagConstraints10.gridy = 4;
		yMaxLabel = new JLabel();
		yMaxLabel.setText("Max");
		GridBagConstraints gridBagConstraints9 = new GridBagConstraints();
		gridBagConstraints9.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints9.gridy = 4;
		gridBagConstraints9.weightx = 0.0;
		gridBagConstraints9.insets = new Insets(0, 5, 5, 0);
		gridBagConstraints9.ipadx = 0;
		gridBagConstraints9.gridx = 1;
		GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
		gridBagConstraints8.gridx = 0;
		gridBagConstraints8.anchor = GridBagConstraints.EAST;
		gridBagConstraints8.insets = new Insets(0, 6, 5, 0);
		gridBagConstraints8.gridy = 4;
		yMinLabel = new JLabel();
		yMinLabel.setText("Min");
		GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
		gridBagConstraints7.fill = GridBagConstraints.VERTICAL;
		gridBagConstraints7.gridy = 3;
		gridBagConstraints7.weightx = 0.0;
		gridBagConstraints7.insets = new Insets(0, 5, 5, 0);
		gridBagConstraints7.anchor = GridBagConstraints.WEST;
		gridBagConstraints7.gridx = 1;
		GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
		gridBagConstraints6.gridx = 0;
		gridBagConstraints6.anchor = GridBagConstraints.EAST;
		gridBagConstraints6.insets = new Insets(0, 6, 5, 0);
		gridBagConstraints6.gridy = 3;
		policyLabel = new JLabel();
		policyLabel.setText("Policy");
		GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
		gridBagConstraints5.gridx = 0;
		gridBagConstraints5.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints5.weightx = 1.0;
		gridBagConstraints5.gridwidth = 4;
		gridBagConstraints5.insets = new Insets(12, 0, 5, 0);
		gridBagConstraints5.gridy = 2;
		yAxisLabel = new JLabelSeparator("Y Axis");
		GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
		gridBagConstraints4.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints4.gridy = 1;
		gridBagConstraints4.weightx = 0.0;
		gridBagConstraints4.insets = new Insets(0, 5, 5, 5);
		gridBagConstraints4.gridx = 3;
		GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
		gridBagConstraints3.gridx = 2;
		gridBagConstraints3.insets = new Insets(0, 5, 5, 0);
		gridBagConstraints3.anchor = GridBagConstraints.EAST;
		gridBagConstraints3.gridy = 1;
		xMaxLabel = new JLabel();
		xMaxLabel.setText("Max");
		GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
		gridBagConstraints2.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints2.gridy = 1;
		gridBagConstraints2.weightx = 0.0;
		gridBagConstraints2.insets = new Insets(0, 5, 5, 0);
		gridBagConstraints2.anchor = GridBagConstraints.CENTER;
		gridBagConstraints2.gridx = 1;
		GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
		gridBagConstraints1.gridx = 0;
		gridBagConstraints1.anchor = GridBagConstraints.EAST;
		gridBagConstraints1.insets = new Insets(0, 6, 5, 0);
		gridBagConstraints1.gridy = 1;
		xMinLabel = new JLabel();
		xMinLabel.setText("Min");
		GridBagConstraints gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints.weightx = 1.0;
		gridBagConstraints.gridwidth = 4;
		gridBagConstraints.insets = new Insets(0, 0, 5, 0);
		gridBagConstraints.gridy = 0;
		xAxisLabel = new JLabelSeparator("X Axis");
		this.setLayout(new GridBagLayout());
		this.setSize(new Dimension(300, 200));
		this.add(xAxisLabel, gridBagConstraints);
		this.add(xMinLabel, gridBagConstraints1);
		this.add(getXMinTextField(), gridBagConstraints2);
		this.add(xMaxLabel, gridBagConstraints3);
		this.add(getXMaxTextField(), gridBagConstraints4);
		this.add(yAxisLabel, gridBagConstraints5);
		this.add(policyLabel, gridBagConstraints6);
		this.add(getPolicyComboBox(), gridBagConstraints7);
		this.add(yMinLabel, gridBagConstraints8);
		this.add(getYMinTextField(), gridBagConstraints9);
		this.add(yMaxLabel, gridBagConstraints10);
		this.add(getYMaxTextField(), gridBagConstraints11);
		this.add(getGluePane(), gridBagConstraints12);
		this.add(getButtonsPane(), gridBagConstraints121);
	}

	private JTextField getXMinTextField() {
		if (xMinTextField == null) {
			xMinTextField = new JTextField();
		}
		return xMinTextField;
	}

	private JTextField getXMaxTextField() {
		if (xMaxTextField == null) {
			xMaxTextField = new JTextField();
		}
		return xMaxTextField;
	}

	private JComboBox getPolicyComboBox() {
		if (policyComboBox == null) {
			policyComboBox = new JComboBox(YAxisPolicy.displayNames());
		}
		return policyComboBox;
	}

	private JTextField getYMinTextField() {
		if (yMinTextField == null) {
			yMinTextField = new JTextField();
		}
		return yMinTextField;
	}

	private JTextField getYMaxTextField() {
		if (yMaxTextField == null) {
			yMaxTextField = new JTextField();
		}
		return yMaxTextField;
	}

	private JPanel getGluePane() {
		if (gluePane == null) {
			gluePane = new JPanel();
		}
		return gluePane;
	}

	private JPanel getButtonsPane() {
		if (buttonsPane == null) {
			buttonsPane = new JPanel();
			buttonsPane.setLayout(new FlowLayout());
			buttonsPane.add(getOkButton(), null);
			buttonsPane.add(getCancelButton(), null);
		}
		return buttonsPane;
	}

	private JButton getOkButton() {
		if (okButton == null) {
			okButton = new JButton();
			okButton.setText("OK");
		}
		return okButton;
	}

	private JButton getCancelButton() {
		if (cancelButton == null) {
			cancelButton = new JButton();
			cancelButton.setText("Cancel");
		}
		return cancelButton;
	}
}
